import { IsInt, IsNotEmpty, IsOptional, IsString, ValidateNested } from "class-validator";
import { BaseQueryDto } from "../base.dto";
import { Transform, Type } from "class-transformer";
import { ApiProperty } from "@nestjs/swagger";

export class CollectAddDto {
    @ApiProperty({ description: "收藏内容, 文件路径" })
    @IsString()
    @IsNotEmpty()
    content: string;
}

class CollectQueryWhereDto {
    @ApiProperty({ description: "搜索content字段" })
    @IsString()
    @IsOptional()
    content?: string;
}

export class CollectQueryDto extends BaseQueryDto {
    @ApiProperty({ type: CollectQueryWhereDto, description: "查找规则" })
    @ValidateNested()
    @Type(() => CollectQueryWhereDto)
    @IsOptional()
    where?: CollectQueryWhereDto;
}

export class CollectRemoveDto {
    @ApiProperty({ description: "数据库id" })
    @IsInt()
    @Transform(({ value }) => parseInt(value))
    id: number;
}

export class CollectUpdateDto extends CollectAddDto {
    @ApiProperty({ description: "数据库id" })
    @IsInt()
    @Transform(({ value }) => parseInt(value))
    id: number;
}
